document.addEventListener("DOMContentLoaded", () => {
    const user = JSON.parse(localStorage.getItem("user"));
    const usernameDisplay = document.querySelector("#username");

    if (!user) {
        alert("请先登录！");
        window.location.href = "login.html";
    } else if (usernameDisplay) {
        usernameDisplay.textContent = user.username;
    }
});